package cn.rkylin.oms.warehouse.shiporder.dao;

import cn.rkylin.core.IDataBaseFactory;
import cn.rkylin.oms.system.shop.vo.ShopVO;
import cn.rkylin.oms.warehouse.shiporder.domain.Shiporder;
import cn.rkylin.oms.warehouse.shiporder.domain.ShiporderSku;
import cn.rkylin.oms.warehouse.shiporder.vo.ShiporderVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 发货DAO
 *
 * @author 齐涛
 * @version 1.0
 * @created 28-9-2017 10:51:30
 */
@Repository(value = "shiporderDAO")
public class ShiporderDAOImpl implements ShiporderDAO {

	@Autowired
	protected IDataBaseFactory dao;

	/**
	 * 查询发货单列表
	 *
	 * @param shiporderVO
	 *            发货单VO
	 * @return 发货单列表
	 * @throws Exception
	 *             异常
	 */
	public List<ShiporderVO> selectShiporderList(ShiporderVO shiporderVO) throws Exception {
		return dao.findAllList("selectShiporderList", shiporderVO);
	}

	/**
	 * 查询发货单列表为取消
	 * 
	 * @param shiporderVO
	 *            发货单VO
	 * @return 发货单列表
	 * @throws Exception
	 *             异常
	 */
	public List<ShiporderVO> selectShiporderListForCancel(ShiporderVO shiporderVO) throws Exception {
		return dao.findAllList("selectShiporderListForCancel", shiporderVO);
	}

	/**
	 * 查询发货单商品列表
	 * 
	 * @param shiporderSku
	 *            发货单商品
	 * @return 发货单商品列表
	 * @throws Exception
	 *             异常
	 */
	public List<ShiporderSku> selectByVOShiporderSku(ShiporderSku shiporderSku) throws Exception {
		return dao.findAllList("selectByVOShiporderSku", shiporderSku);
	}

	/**
	 * 查询发货单信息
	 *
	 * @param shiporderVO
	 *            发货单VO
	 * @return 发货单信息
	 * @throws Exception
	 *             异常
	 */
	public ShiporderVO getShiporderInfo(ShiporderVO shiporderVO) throws Exception {
		List<ShiporderVO> list = dao.findAllList("getShiporderInfo", shiporderVO);

		if (list != null && list.size() > 0) {
			return list.get(0);
		}

		return null;
	}

	/**
	 * 更新发货单
	 *
	 * @param shiporder
	 *            发货单bean
	 * @return 更新条数
	 * @throws Exception
	 *             异常
	 */
	public int updateShiporder(Shiporder shiporder) throws Exception {
		return dao.update("updateShiporder", shiporder);
	}

	/**
	 * 系统发货单主表信息插入数据库
	 *
	 * @param shiporderVO
	 * @return
	 * @throws Exception
	 */
	public int insertSelectiveShiporder(ShiporderVO shiporderVO) throws Exception {
		return dao.insert("insertSelectiveShiporder", shiporderVO);
	}

	/**
	 * 系统发货单商品明细表信息插入数据库
	 *
	 * @param shiporderSku
	 * @return
	 * @throws Exception
	 */
	public int insertSelectiveShiporderSku(ShiporderSku shiporderSku) throws Exception {
		return dao.insert("insertSelectiveShiporderSku", shiporderSku);
	}

	/**
	 * 查询需要平台发货的信息
	 */
	@Override
	public List<ShiporderVO> selectByShopVoShipOrderConsign(ShopVO shopVO) throws Exception {
		return dao.findAllList("selectByShopVoShipOrderConsign", shopVO);
	}

	/**
	 * 更新
	 */
	@Override
	public int updateByPrimaryKeySelectiveShipOrder(ShiporderVO shiporderVO) throws Exception {
		return dao.update("updateByPrimaryKeySelectiveShipOrder", shiporderVO);
	}

}
